*This file creates figure D.3 of different specifications

*********************
*Joint with Norway first 
*********************

use  "$path/ind_ddd.dta", clear

global sharecontrols2 c.ln_value_prod1943#year c.lnlabor_all1943#year 

drop if year==1970

gen g1=(year>=1934&year<=1936)
gen g2=(year>=1937&year<=1939)
gen g3=(year>=1940&year<=1942)
gen g4=(year==1943)
gen g5=(year>=1944&year<=1946)
gen g6=(year>=1947&year<=1949)
gen g7=(year>=1950&year<=1952)
gen g8=(year>=1953&year<=1955)
gen g9=(year>=1956&year<=1958)
gen g10=(year>=1959&year<=1961)
gen g11=(year>=1962&year<=1964)
gen g12=(year>=1965&year<=1967)
gen g13=(year>=1968&year<=1970)

forvalues x=1(1)13{
	gen repaml`x'=g`x'*finland*$treat
	}
	
	forvalues x=1(1)13{
	gen repam`x'=g`x'*$treat
	}
	
	forvalues x=1(1)13{
	gen fin`x'=g`x'*finland
	}

local repaflexible2 " repaml1 repaml2 repaml3 repaml5  repaml6 repaml7 repaml8 repaml9 repaml10 repaml11 repaml12 repaml13 "
local repaflexible1 " repam1 repam2 repam3 repam5  repam6 repam7 repam8 repam9 repam10 repam11 repam12 repam13 "
local finflex " fin1 fin2 fin3 fin4  fin5  fin7 fin8 fin9 fin10 fin11 fin12 fin13 "

tempfile  p21 p22 p23

parmby  "reghdfe ln_value_prod `repaflexible2'  `repaflexible1' `finflex' , absorb(year_country isic_country  $sharecontrols2) vce(cluster isic_country)", lab saving(`"`p21'"',replace) idn(1) ids(Unadjusted)


preserve
clear all
set obs 1
gen year =4
gen estimate = 0
gen parm ="repaml4"
gen min95 =0
gen max95 =0
append using `p21'
keep if regexm(parm, "^repam*")
replace parmseq=parmseq+1 if parmseq>3
replace parmseq=year if parmseq==.
rename parmseq yearstr
keep if yearstr<14
sort yearstr
save  "$path/NorwayprodDDD_group.dta" , replace

restore 

local repaflexible2 " repaml1 repaml2 repaml3 repaml5  repaml6 repaml7 repaml8 repaml9 repaml10 repaml11 repaml12 repaml13 "
local repaflexible1 " repam1 repam2 repam3 repam5  repam6 repam7 repam8 repam9 repam10 repam11 repam12 repam13 "
local finflex " fin1 fin2 fin3 fin4  fin5  fin7 fin8 fin9 fin10 fin11 fin12 fin13 "

tempfile  p21 p22 p23

parmby  "reghdfe lnlabor_all `repaflexible2'  `repaflexible1' `finflex' , absorb(year_country isic_country  $sharecontrols2) vce(cluster isic_country)", lab saving(`"`p21'"',replace) idn(1) ids(Unadjusted)


preserve
clear all
set obs 1
gen year =4
gen estimate = 0
gen parm ="repaml4"
gen min95 =0
gen max95 =0
append using `p21'
keep if regexm(parm, "^repam*")
replace parmseq=parmseq+1 if parmseq>3
replace parmseq=year if parmseq==.
rename parmseq yearstr
keep if yearstr<14
sort yearstr
*title(Panel B: ln Labor Force)
tempfile lddddg
save  "$path/NorlaborDDD_group.dta" , replace

restore

*********************
*Finland 
*********************

*Aggreagated to groups

**Labor

global home  "/Users/mattimit"

use "$path/industry_data.dta", clear

cd "$graphs"

global controls43 c.power_labor_share1943#year    ///
 c.ln_value_prod1943#year  c.lnlabor_all1943#year c.ln_relative_wage1943#year c.ln_establishments1943#year c.skilled1943#year c.ln_inputs_all1943#year c.ln_valueadded1943#year 
 
global controls38 c.power_labor_share1938#year    ///
 c.ln_value_prod1938#year  c.lnlabor_all1938#year c.ln_relative_wage1938#year c.ln_establishments1938#year c.skilled1938#year c.ln_inputs_all1938#year
 
global sharecontrols c.lnlabor_all1943#year  c.power_labor_share1943#year c.ln_relative_wage1943#year c.ln_establishments1943#year c.skilled1943#year c.ln_inputs_all1943#year c.ln_valueadded1943#year 

gen g1=(year>=1934&year<=1936)
gen g2=(year>=1937&year<=1939)
gen g3=(year>=1940&year<=1942)
gen g4=(year==1943)
gen g5=(year>=1944&year<=1946)
gen g6=(year>=1947&year<=1949)
gen g7=(year>=1950&year<=1952)
gen g8=(year>=1953&year<=1955)
gen g9=(year>=1956&year<=1958)
gen g10=(year>=1959&year<=1961)
gen g11=(year>=1962&year<=1964)
gen g12=(year>=1965&year<=1967)
gen g13=(year>=1968&year<=1970)

forvalues x=1(1)13{
	gen repam`x'=g`x'*treat_std_l 
	}

local repaflexible1 " repam1 repam2 repam3 repam5  repam6 repam7 repam8 repam9 repam10 repam11 repam12 repam13 "

tempfile  p11 p12 p13

parmby  "reghdfe lnlabor_all  `repaflexible1' , absorb(year isic  $sharecontrols) vce(cluster isic)", lab saving(`"`p11'"',replace) idn(1) ids(Unadjusted)


preserve
clear all
set obs 1
gen year =4
gen estimate = 0
gen parm ="repam4"
gen min95 =0
gen max95 =0
append using `p11'
keep if regexm(parm, "^repam*")
replace parmseq=parmseq+1 if parmseq>3
replace parmseq=year if parmseq==.
rename parmseq yearstr
sort yearstr
*title(Panel B: ln Labor Force)
tempfile tlabor1
save `tlabor1'

restore

****W/o Established industries  

parmby  "reghdfe lnlabor_all  `repaflexible1' if timberpaper==0, absorb(year isic  $sharecontrols) vce(cluster isic)", lab saving(`"`p12'"',replace) idn(1) ids(Unadjusted)

preserve

clear all
set obs 1
gen year =4
gen estimate = 0
gen parm ="repam4"
gen min95 =0
gen max95 =0
append using `p12'
keep if regexm(parm, "^repam*")
replace parmseq=parmseq+1 if parmseq>3
replace parmseq=year if parmseq==.
rename parmseq yearstr

sort yearstr
*title(Panel B: ln Labor Force)
tempfile tlabor2
save `tlabor2'

restore


*Robust to all controls  

global controls43 c.power_labor_share1943#year    ///
c.ln_value_prod1943#year  c.lnlabor_all1943#year c.ln_relative_wage1943#year c.ln_establishments1943#year c.skilled1943#year c.ln_inputs_all1943#year c.ln_valueadded1943#year 
 
global controls38 c.power_labor_share1938#year    ///
c.ln_value_prod1938#year  c.lnlabor_all1938#year c.ln_relative_wage1938#year c.ln_establishments1938#year c.skilled1938#year c.ln_inputs_all1938#year
 
parmby  "reghdfe lnlabor_all  `repaflexible1'  $controls43 , absorb(year isic  $sharecontrols) vce(cluster isic)", lab saving(`"`p13'"',replace) idn(1) ids(Unadjusted)


preserve
clear all
set obs 1
gen year =4
gen estimate = 0
gen parm ="repam4"
gen min95 =0
gen max95 =0
append using `p13'
keep if regexm(parm, "^repam*")
replace parmseq=parmseq+1 if parmseq>3
replace parmseq=year if parmseq==.
rename parmseq yearstr
sort yearstr
tempfile tlabor3
save `tlabor3'
restore


***Combine

preserve

use `tlabor1', clear
rename estimate estimate_base
rename min95 min95_base
rename max95 max95_base
joinby yearstr using `tlabor2'
gen yearstr_base=yearstr-0.2
rename estimate estimate_ntp
rename min95 min95_ntp
rename max95 max95_ntp
joinby yearstr using `tlabor3'
gen yearstr_ntp=yearstr+0.2


twoway  (scatter estimate_base yearstr_base , msize(medium) mcolor(maroon))  (rspike   min95_base max95_base yearstr_base , lcolor(maroon)) (scatter estimate_ntp yearstr_ntp , msize(medium) mcolor(blue))  (rspike   min95_ntp max95_ntp yearstr_ntp , lcolor(blue))  (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy))  ,  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel B: Estimates of ln Labor Force")   xlabel(1 "1934-1936" 2 "1937-1939" 3 "1940-1942" 4 "1943" 5 "1944-1946" 6 "1947-1949" 7 "1950-1952" 8 "1953-1955" 9 "1956-1958" 10 "1959-1961" 11 "1962-1964" 12 "1965-1967" 13 "1968-1970", angle(vertical) ) plotregion(lcolor(black)) graphregion(lcolor(black) fcolor(white) color(white)) legend(order(1 "Baseline estimate" 3 "Baseline estimate without established" 5 "Full controls"))   xlabel(,grid nogextend ) ytitle("", margin(0 1 0 0)) ylabel(-.2 -.1 0 .1 .2 .3 .4) ytick(-.1 0 .1 .2 .3 .4, grid)  xline(5) xline(7)  saving(flexible_labor.gph, replace)
restore


preserve
use `tlabor1', clear
rename estimate estimate_base
rename min95 min95_base
rename max95 max95_base
joinby yearstr using `tlabor2'
gen yearstr_base=yearstr-0.2
rename estimate estimate_ntp
rename min95 min95_ntp
rename max95 max95_ntp
joinby yearstr using  "$path/NorlaborDDD_group.dta" 
rename estimate estimate_nor
rename min95 min95_nor
rename max95 max95_nor
gen yearstr_nor=yearstr+0.4
joinby yearstr using `tlabor3'
gen yearstr_ntp=yearstr+0.2
 
twoway  (scatter estimate_base yearstr_base , msize(medium) mcolor(maroon))  (rspike   min95_base max95_base yearstr_base , lcolor(maroon)) (scatter estimate_ntp yearstr_ntp , msize(medium) mcolor(blue))  (rspike   min95_ntp max95_ntp yearstr_ntp , lcolor(blue))  (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_nor yearstr_nor , msize(medium) mcolor(green))  (rcap   min95_nor max95_nor yearstr_nor , lcolor(dkgreen)) ,  xsize(6) ysize(4) xtitle(Year, ) title("Panel B: Estimates of ln Labor Force")   xlabel(1 "1934-1936" 2 "1937-1939" 3 "1940-1942" 4 "1943" 5 "1944-1946" 6 "1947-1949" 7 "1950-1952" 8 "1953-1955" 9 "1956-1958" 10 "1959-1961" 11 "1962-1964" 12 "1965-1967" 13 "1968-1970", angle(vertical) ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "Baseline DD estimate" 3 "Baseline DD estimate without established" 5 "DD estimate with full controls" 7 "Baseline Norway DDD estimate") position(6))   xlabel(,grid nogextend ) ytitle("", margin(0 1 0 0)) ylabel(-.1 0 .1 .2 .3 .4) ytick(-.1 0 .1 .2 .3 .4, grid)  xline(5) xline(7)   saving("$graphs/flexible_labor_DDD.gph", replace)
restore


**************
**Production
*****************

use  "$path/industry_data.dta", clear

gen g1=(year>=1934&year<=1936)
gen g2=(year>=1937&year<=1939)
gen g3=(year>=1940&year<=1942)
gen g4=(year==1943)
gen g5=(year>=1944&year<=1946)
gen g6=(year>=1947&year<=1949)
gen g7=(year>=1950&year<=1952)
gen g8=(year>=1953&year<=1955)
gen g9=(year>=1956&year<=1958)
gen g10=(year>=1959&year<=1961)
gen g11=(year>=1962&year<=1964)
gen g12=(year>=1965&year<=1967)
gen g13=(year>=1968&year<=1970)

forvalues x=1(1)13{
	gen repam`x'=g`x'*treat_std_l 
	}

local repaflexible1 " repam1 repam2 repam3 repam5  repam6 repam7 repam8 repam9 repam10 repam11 repam12 repam13 "

tempfile  p21 p22 p23

parmby  "reghdfe ln_value_prod  `repaflexible1' , absorb(year isic  $sharecontrols) vce(cluster isic)",lab saving(`"`p21'"',replace) idn(1) ids(Unadjusted)


preserve
clear all
set obs 1
gen year =4
gen estimate = 0
gen parm ="repam4"
gen min95 =0
gen max95 =0
append using `p21'
keep if regexm(parm, "^repam*")
replace parmseq=parmseq+1 if parmseq>3
replace parmseq=year if parmseq==.
rename parmseq yearstr
sort yearstr
*title(Panel B: ln Labor Force)
tempfile tprod1
save `tprod1'
restore


****W/o Established 

parmby  "reghdfe ln_value_prod  `repaflexible1' if timberpaper==0, absorb(year isic  $sharecontrols) vce(cluster isic)", lab saving(`"`p22'"',replace) idn(1) ids(Unadjusted)

preserve
clear all
set obs 1
gen year =4
gen estimate = 0
gen parm ="repam4"
gen min95 =0
gen max95 =0
append using `p22'
keep if regexm(parm, "^repam*")
replace parmseq=parmseq+1 if parmseq>3
replace parmseq=year if parmseq==.
rename parmseq yearstr
sort yearstr
*title(Panel B: ln Labor Force)
tempfile tprod2
save `tprod2'
restore


*Robust to all controls  

local repaflexible1 " repam1 repam2 repam3 repam5  repam6 repam7 repam8 repam9 repam10 repam11 repam12 repam13 "

global controls43 c.power_labor_share1943#year    ///
c.ln_value_prod1943#year  c.lnlabor_all1943#year c.ln_relative_wage1943#year c.ln_establishments1943#year c.skilled1943#year c.ln_inputs_all1943#year c.ln_valueadded1943#year 
 
global controls38 c.power_labor_share1938#year    ///
c.ln_value_prod1938#year  c.lnlabor_all1938#year c.ln_relative_wage1938#year c.ln_establishments1938#year c.skilled1938#year c.ln_inputs_all1938#year
 

tempfile  p21 p22 p23
parmby  "reghdfe ln_value_prod  `repaflexible1'  , absorb(year isic  $controls43 ) vce(cluster isic)", lab saving(`"`p23'"',replace) idn(1) ids(Unadjusted)


preserve
clear all
set obs 1
gen year =4
gen estimate = 0
gen parm ="repam4"
gen min95 =0
gen max95 =0
append using `p23'
keep if regexm(parm, "^repam*")
replace parmseq=parmseq+1 if parmseq>3
replace parmseq=year if parmseq==.
rename parmseq yearstr
keep if yearstr<14
sort yearstr
*title(Panel B: ln Labor Force)
tempfile tprod3
save `tprod3'
restore


***Combine

preserve
use `tprod1', clear
rename estimate estimate_base
rename min95 min95_base
rename max95 max95_base
joinby yearstr using `tprod2'
gen yearstr_base=yearstr-0.2
rename estimate estimate_ntp
rename min95 min95_ntp
rename max95 max95_ntp
joinby yearstr using  "$path/NorwayprodDDD_group.dta" 
rename estimate estimate_nor
rename min95 min95_nor
rename max95 max95_nor
gen yearstr_nor=yearstr+0.4
joinby yearstr using `tprod3'
gen yearstr_ntp=yearstr+0.2
twoway  (scatter estimate_base yearstr_base , msize(medium) mcolor(maroon))  (rspike   min95_base max95_base yearstr_base , lcolor(maroon)) (scatter estimate_ntp yearstr_ntp , msize(medium) mcolor(blue))  (rspike   min95_ntp max95_ntp yearstr_ntp , lcolor(blue))  (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_nor yearstr_nor , msize(medium) mcolor(green))  (rcap   min95_nor max95_nor yearstr_nor , lcolor(dkgreen))  ,  xsize(6) ysize(4) xtitle(Year, )  title("Panel A: Estimates of ln Value of Production")   xlabel(1 "1934-1936" 2 "1937-1939" 3 "1940-1942" 4 "1943" 5 "1944-1946" 6 "1947-1949" 7 "1950-1952" 8 "1953-1955" 9 "1956-1958" 10 "1959-1961" 11 "1962-1964" 12 "1965-1967" 13 "1968-1970", angle(vertical) ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "Baseline DD estimate" 3 "Baseline DD estimate without established" 5 "DD estimate with full controls" 7 "Baseline Norway DDD estimate") position(6))   xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))  xline(5) xline(7)  saving("$graphs/flexible_prod_robust_group_DDD.gph", replace)

restore

*Combine 

cd "$graphs/"

graph combine flexible_prod_robust_group_DDD.gph flexible_labor_DDD.gph,  col(2) row(1) iscale(.6) ysize(4.5) xsize(14) commonscheme  graphregion(fcolor(white) color(white))

graph export "$graphs/combined_flexible_group_wnor_sized2.eps",as(eps)   font(Times) replace
graph export "$graphs/combined_flexible_group_wnor_sized2.pdf",as(pdf)   font(Times) replace

graph export "$graphs/combined_flexible_group_wnor_sized2.eps",as(eps)   font(Times) replace


